/* o
*
 * Author: J Conrad Stack
 *         jcstack
 * 
 * Program 4: 
 * a collection of methods which perform various mathmatical procedures.
 * 
 */ 


#include "userMath.h"




/*
*
 * purpose: to check if a number is prime
 * parameters: n should be a number
 * returns: 1 if number is prime and greater than 1, 0 if not
 * side-effects: none
 * sample-call: isPrime(18) returns 0, since 18 is divisible by itself and 9, and is therefore not prime
 */ 
int isPrime(int n);

int findSum(int n, int m){
    if(n < 0 | m < 0)
        return 0;
    if(n > m )
        return 0;
    if(n == m)
        return m;

    return n + (findSum(n+1,m));

}


unsigned long findProduct(int n, int m){
    if(n < 0 | m < 0)
        return 0;
    if(n > m )
        return 0;
    if(n == m)
        return m;
    
    return n * (findProduct(n+1,m));
}


int inOrder(int n,...){
    va_list argList;
    int i;
    double temp;
    double temp2;

    if(n==0)
        return 0;

    va_start(argList,n);
    temp = 0.0;
    for(i=0;i<n;i++){
        temp2 = va_arg(argList, double);
        if(temp > temp2){
            return 0;
        }

        temp = temp2;
    }
    va_end(argList);
    return 1;
}

int arePrime(int n,...){
    va_list argList;
    int i;
    va_start(argList,n);

    if(n==0)
        return 0;

    for(i=0;i<n;i++){
        if((isPrime(va_arg(argList,int))) == 0){
            return 0;
        }
    }
    return 1;
}



int isPrime(int n){
    int temp = 2;
    if(n <= 1)
        return 0;

    while (temp < n) {
        if(n%temp == 0)
            return 0;
        temp++;
    }
    return 1;
}
